<?php 

/**
* 个人中心控制器
*/
class MenberController extends CommonController{
	private $uid;
	private $cateData;
	/**
	 * [__init 构造函数]
	 * @return [type] [description]
	 */
	public function __init(){
		parent::__init();
		if (!isset($_SESSION['uid'])) {
            $this->success('未登录,请先登录',U('Login/index'));
        }
        $this->uid = intval($_SESSION['uid']);
        $cateData = K('Category')->get_data();
    	// $cateData= Data::tree($cateData,'cname','cid','pid');
    	// p($cateData);
    	$arr = array();
    	foreach ($cateData as $k => $v) {
    		if ($v['pid']==0) {
    			$arr[$k]= $v;
    			$arr[$k]["son"]=$this->get_son($cateData,$v['cid']);
    		}
    	}
    	$this->cateData = $arr;
	}
	/**
	 * [index 首页动作]
	 * @return [type] [description]
	 */
	public function index(){
       	// 用户订单信息
        $orderData = K('Order')->get_data(array('uid'=>$this->uid));
        // p($orderData);
        // 分配变量
        $this->assign('cateData',$this->cateData);
        $this->assign('orderData',$orderData);
		// 显示视图
		$this->dis('menber.html');
	}
	/**
	 * [order 用户订单页面]
	 * @return [type] [description]
	 */
	public function order(){
		// 用户订单信息
        $orderData = K('Order')->get_data(array('uid'=>$this->uid));

		// 分配变量
		$this->assign('orderData',$orderData);
		$this->assign('cateData',$this->cateData);
		// 显示视图
		$this->dis('m_order.html');
	}
	/**
	 * [m_detail 订单详情]
	 * @return [type] [description]
	 */
	public function detail(){
		$oid = Q('get.oid',0,'intval');
		$orderData =K('Order')->get_one_data(array('oid'=>$oid));
		$orderListData =K('OrderList')->get_data(array('oid'=>$oid));
		// var_dump($orderData);
		foreach ($orderListData as $k => $v) {
			$orderListData[$k]['price']=intval($v['subtotal'])/intval($v['quantity']);
		}
		// 分配变量
		$this->assign('cateData',$this->cateData);
		$this->assign('orderData',$orderData);
		$this->assign('orderListData',$orderListData);
		// 显示视图
		$this->dis('m_detail.html');
	}

	public function store(){
		$storeData = K('StoreGoodsView')->get_data(array('uid'=>$this->uid));
		// 分配变量
		$this->assign('cateData',$this->cateData);
		$this->assign('storeData',$storeData);
		// 显示视图
		$this->dis('m_store.html');
	}
	public function comment(){
		// 用户订单信息
        $orderData = K('Order')->get_data(array('uid'=>$this->uid));
        foreach ($orderData as $k =>  $v) {
        	$orderData[$k]['list']=K('OrderList')->get_data(array('oid'=>$v['oid']));
        }
        // p($orderData);
		// 分配变量
		$this->assign('orderData',$orderData);
		$this->assign('cateData',$this->cateData);
		// 显示视图
		$this->dis('m_comment.html');
	}
}














 ?>